package Demo_A;


public class Demo_A {
    public static boolean flag = true;

    public static void main(String[] args) throws InterruptedException {
        Thread t = new Thread(() -> {
            while(flag) {
                System.out.println("hello thread");
                try {
                    Thread.sleep(1000);
                } catch (InterruptedException e) {
                    throw new RuntimeException(e);
                }
            }
        });

        //启动线程
        t.start();

        //让t线程执行 5 秒
        Thread.sleep(5000);

        //中断线程
        flag = false;

    }
}
